from shapely.geometry import shape,mapping
import shapely
class Sqlresult2Stac():
    def __init__(self):

        self.stacdict={ "type":"FeatureCollection","context":[],"features":[]}

    def values(self,result,index:int)->list:
        return result["column_{}".format(str(index))]
    
    def merfeild(self,result)->list:
        results=[]
        
        for i in range(len(result["column_1"])):
            geojsons={}
            geojsons["datapk"]=result["column_1"][i]
            geojsons["id"]=result["column_2"][i]
            geojsons["SlID"]=result["column_3"][i]
            geojsons["ImgGSD"]=result["column_4"][i]
            geojsons["SensorId"]=result["column_5"][i]
            geojsons["Cloud"]=result["column_6"][i]
            geojsons["datetime"]=result["column_7"][i]
            geojsons["geometry"]=mapping(shapely.from_wkt(result["column_8"][i]))
            results.append(geojsons)
        return results
    def to_stacdict(self,context:dict,features:list) ->dict:
        result=self.stacdict.copy()
        result["context"]=context
        result["features"]=features
        return result